Skip to content

Conversation

@alexsch01
Copy link
Contributor

@alexsch01 alexsch01 commented Nov 10, 2025

This issue happens when a synchronous request is intercepted and the routeHandler argument to cy.intercept is given


The second part of this PR (prevent cross origin cookies from breaking sync requests)

  • prevents the browser from freezing when a sync request is made through the cross origin runner

Additional details

Steps to test

How has the user experience changed?

PR Tasks


Note

Detects synchronous XHRs, skips awaiting route handlers and cookie sync that would block, adds XHR patches to flag sync requests, and updates tests/changelog.

  • Network/Proxy:
    • Add req.isSyncRequest (parsed from x-cypress-is-sync-request) and use it to:
      • Skip cy.intercept() route-handler awaiting for sync XHRs with a warning in intercepted-request.
      • Bypass waiting for cross:origin:cookies:received on sync requests with a warning in response middleware.
    • Extract and clear new header in request middleware; unit tests added.
    • Extend CypressIncomingRequest type with isSyncRequest.
  • Runner/Injection:
    • Patch XMLHttpRequest.open to set x-cypress-is-sync-request when async=false (both main and cross-origin bundles).
    • Cross-origin patches reorganized under patches/cross-origin/* and imports updated.
    • Cross-origin XHR patch reports credentials asynchronously only for async requests.
  • Driver:
    • Update imports to new cross-origin patch paths.
  • Tests:
    • Add e2e specs for syncing XHR with route handler and cy.origin with cookie.
    • Add unit tests for new header extraction behavior.
  • Docs/Changelog:
    • Add bugfix entry describing freeze on intercepted synchronous requests.

Written by Cursor Bugbot for commit 39a2fa3. This will update automatically on new commits. Configure here.

@alexsch01 alexsch01 marked this pull request as draft November 10, 2025 15:06
@cypress-app-bot
Copy link
Collaborator

@alexsch01 alexsch01 marked this pull request as ready for review November 10, 2025 15:31
@mschile
Copy link
Contributor

mschile commented Nov 13, 2025

Hi @alexsch01 👋🏼, thanks for opening this PR! Just to make sure I understand the proposed changes, this would resolve the freezing issue but the routeHandler of the intercepted request would not be executed. Is my understanding correct?

@alexsch01
Copy link
Contributor Author

Hi @alexsch01 👋🏼, thanks for opening this PR! Just to make sure I understand the proposed changes, this would resolve the freezing issue but the routeHandler of the intercepted request would not be executed. Is my understanding correct?

The routeHandler is executed but the request that goes to the server won't be modified

req.headers["foo"] = "bar"

The server will not get this since it's not resolved, but anything you console.log in the routeHandler will print in DevTools console

@mschile
Copy link
Contributor

mschile commented Nov 14, 2025

Ok, I see the before:request event is still emitted but since this is a sync request, the event is received after the sync request has already been fully processed. I'm going to discuss this further with the team but my initial thought is that we should skip the adding the subscriptions entirely here.

@alexsch01
Copy link
Contributor Author

The second part of the fix (7b4f2e7) fixes a freezing issue when there's a sync request in cy.origin block

The downside is cross-origin cookies most likely won't work in this case

In cases where you must use cy.origin due to navigating to a different subdomain, this allows the test to work as expected when there's a sync request

@mschile
Copy link
Contributor

mschile commented Nov 14, 2025

Thanks for cross origin explanation. I'll have to look into it further.

@mschile
Copy link
Contributor

mschile commented Nov 18, 2025

@alexsch01, I discussed this PR with the rest of the team and we are good with proceeding. We should skip adding the subscriptions entirely here so the routeHandler won't get run. We would also like to log out some warnings to the terminal to inform the user that the sync request was not intercepted and for the cross-origin case that cookies may not have been applied.

@alexsch01
Copy link
Contributor Author

@mschile I skipped adding the subscriptions entirely for sync requests and added the 2 warnings

Let me know how that looks

Copy link
Contributor

@mschile mschile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall! Made a few changes. Let's go ahead and add some unit and e2e tests.

@alexsch01
Copy link
Contributor Author

alexsch01 commented Nov 21, 2025

Looks good overall! Made a few changes. Let's go ahead and add some unit and e2e tests.

made some tests, your changes look good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser will freeze when sync request is intercepted

4 participants